﻿using System;
using System.Collections.Generic;
using System.Text;

namespace dotHTML.HTML {
    /// <summary>
    /// Defines an HTML anchor (&lt;A&gt;).
    /// </summary>
    [Serializable]
    public class A : Element {

        private IList<string> _charset;
        private IList<int> _coords;
        private string _href;
        private string _hreflang;
        private string _media;
        private string _name;
        private ICollection<string> _ping;
        private ICollection<string> _rel;
        private string _rev;
        private ShapeChoices? _shape;
        private string _target;
        private string _type;

        /// <summary>
        /// Creates a new instance of an HTML anchor.
        /// </summary>
        public A() {
            _charset = new List<string>();
            _coords = new List<int>();
            _ping = new LinkedList<string>();
            _rel = new LinkedList<string>();
        }

        /// <summary>
        /// Creates a new instance of an HTML anchor.
        /// </summary>
        /// <param name="href"></param>
        /// <param name="text"></param>
        public A(string href, string text) : this() {
            this._href = href;
            this.Children.Add(new TextNode(text));
        }

        /// <summary>
        /// Gets the character set for the linked resource.
        /// </summary>
        [Obsolete("Deprecated in HTML5. Use the HTTP Content-Type header instead.")]
        public IList<string> Charset {
            get { return _charset; }
        }

        /// <summary>
        /// Gets a list of coordinates for this element.
        /// </summary>
        [Obsolete("Deprecated in HTML5.")]
        public IList<int> Coords {
            get { return _coords; }
        }

        /// <summary>
        /// Gets or sets the link target for this link.
        /// </summary>
        public string Href {
            get { return _href; }
            set { _href = value; }
        }

        /// <summary>
        /// Gets or sets the language of the link target.
        /// </summary>
        public string HrefLang {
            get { return _hreflang; }
            set { _hreflang = value; }
        }

        /// <summary>
        /// Gets the media query associated with this link.
        /// </summary>
        public string Media {
            get { return _media; }
            set { _media = value; }
        }

        /// <summary>
        /// Gets or sets the name of this link.
        /// </summary>
        [Obsolete("Deprecated in HTML5. Use \"id\" instead.")]
        public string Name {
            get { return _name; }
            set { _name = value; }
        }

        /// <summary>
        /// Gets a collection of all URLs to ping when the link is clicked.
        /// </summary>
        public ICollection<string> Ping {
            get { return _ping; }
        }

        /// <summary>
        /// Gets a collection of all this link's relationships to the linked
        /// content.
        /// </summary>
        public ICollection<string> Rel {
            get { return _rel; }
        }

        /// <summary>
        /// Gets the reverse link of this link.
        /// </summary>
        [Obsolete("Deprecated in HTML5.")]
        public string Rev {
            get { return _rev; }
            set { _rev = value; }
        }

        /// <summary>
        /// Gets or sets the shape choice for this link. Set to null to omit.
        /// </summary>
        [Obsolete("Deprecated in HTML5 - use <img> and <map>.")]
        public ShapeChoices? Shape {
            get { return _shape; }
            set { _shape = value; }
        }

        /// <summary>
        /// Gets or sets the target of this link.
        /// </summary>
        public string Target {
            get { return _target; }
            set { _target = value; }
        }

        /// <summary>
        /// Gets or sets the MIME type associated with the link target.
        /// </summary>
        public string Type {
            get { return _type; }
            set { _type = value; }
        }

        /// <summary>
        /// Writes out the local attributes of this anchor.
        /// </summary>
        /// <param name="sb">The StringBuilder to write this element's
        /// attribute data to.</param>
        protected override void WriteLocalAttributes(StringBuilder sb) {
            AttributeWriter.Write(sb, _charset, "charset", ' ');
            AttributeWriter.Write(sb, _coords, "coords", ',');
            AttributeWriter.Write(sb, _href, "href");
            AttributeWriter.Write(sb, _hreflang, "hreflang");
            AttributeWriter.Write(sb, _media, "media");
            AttributeWriter.Write(sb, _name, "name");
            AttributeWriter.Write(sb, _ping, "ping", ' ');
            AttributeWriter.Write(sb, _rel, "rel", ' ');
            AttributeWriter.Write(sb, _rev, "rev");
            AttributeWriter.Write(sb, _shape, "shape", true);
            AttributeWriter.Write(sb, _target, "target");
            AttributeWriter.Write(sb, _type, "type");
        }
    }
}
